#include<iostream>
using namespace std;

class Solution
{
public:
    string capitalizeTitle(string title)
    {
        title += ' ';
        int left = 0, right = 0;
        while ((right = title.find(' ', left)) != -1)
        {
            if (right - left <= 2)
            {
                title[left] = tolower(title[left]);
                title[right - 1] = tolower(title[right - 1]);
            }
            else
            {
                title[left] = toupper(title[left]);
                left++;
                while (left < right)
                {
                    title[left] = tolower(title[left]);
                    left++;
                }
            }
            left = right + 1;
        }
        title.erase(title.size() - 1);
        return title;
    }

};

int main()
{
    Solution s;
    string str("capiTalIze tHe titLe");
    string ss=s.capitalizeTitle(str);
    cout << ss << endl;
    return 0;
}